/*
    3.5 Implement a MyQueue class which implements a queue using two stacks.
*/
class TwoStacksQueue<T> {
    private StackImpl<T> eldest = new StackImpl<T>();
    private StackImpl<T> newest = new StackImpl<T>();

    public int size() {
        return eldest.size + newest.size;
    }

    public void push(T element) {
        newest.push(element);
    }

    public T pop() {
        shiftStacks();
        return eldest.pop();
    }

    public T peek() {
        shiftStacks();
        return eldest.peek();
    }

    private void shiftStacks() {
        if (eldest.isEmpty()) {
            while (!newest.isEmpty()) eldest.push(newest.pop());
        }
    }
}
